<div class="layui-fluid">
    <div class="layui-row">
        <form action="" method="post" class="layui-form layui-form-pane">
            <div class="layui-form-item">
                <label for="name" class="layui-form-label">
                    <span class="x-red">*</span>角色名
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="name" name="name" required="" lay-verify="required"
                           autocomplete="off" value="{{.info.Name}}" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">
                    拥有权限
                </label>
                <table  class="layui-table layui-input-block">
                    <tbody>
                    {{range .treeMenus}}
                        <tr>
                            <td>
                                <input type="checkbox" lay-skin="primary" lay-filter="father" title="{{.Name}}" value="{{.Id}}">
                            </td>
                            <td>
                                <div class="layui-input-block">
                                    {{range $elem := .Children}}
                                        <input name="rule[]" {{if eq $.info.Rules "*" }} checked {{else if list_in_slice $.rules .Id }} checked {{end}} lay-skin="primary" type="checkbox" title="{{$elem.Name}}" value="{{$elem.Id}}">
                                    {{end}}
                                </div>
                            </td>
                        </tr>
                    {{end}}
                    </tbody>
                </table>
            </div>
            <div class="layui-form-item layui-form-text">
                <label for="desc" class="layui-form-label">
                    描述
                </label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入内容" id="remark" name="remark" class="layui-textarea">{{.info.Remark}}</textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <button class="layui-btn" lay-submit="update" lay-filter="update">更新</button>
            </div>
        </form>
    </div>
</div>
<script>
    layui.use(['form','layer'], function(){
        $ = layui.jquery;
        var form = layui.form
            ,layer = layui.layer;

        //监听提交
        form.on('submit(update)', function(data){
            request_post("/admin/group/update/{{.info.Id}}",data.field).then(function (data) {
                layer.alert("更新成功", {
                        icon: 6
                    },
                    function() {
                        //关闭当前frame
                        xadmin.close();

                        // 可以对父窗口进行刷新
                        xadmin.father_reload();
                    });
            },function (error) {
                msg_error(error.msg)
            })
            return false;
        });


        form.on('checkbox(father)', function(data){
            if(data.elem.checked){
                $(data.elem).parent().siblings('td').find('input').prop("checked", true);
                form.render();
            }else{
                $(data.elem).parent().siblings('td').find('input').prop("checked", false);
                form.render();
            }
        });


    });
</script>